package com.sugon.service.impl;

import com.sugon.cache.J2CacheUtils;
import com.sugon.dao.DevPlanGcDao;
import com.sugon.entity.DevPlanGcEntity;
import com.sugon.service.DevPlanGcService;
import com.sugon.service.DevReportUrgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 设备维护工单Service实现类
 *
 * @author sugon
 * @date 2020-03-10 19:33:09
 */
@Service("devPlanGcService")
public class DevPlanGcServiceImpl implements DevPlanGcService {

    @Autowired
    private DevPlanGcDao devPlanGcDao;
    @Autowired
    private DevReportUrgeService devReportUrgeService;

    /**
     * queryObject
     *
     * @param id 主键
     * @return
     */
    @Override
    public DevPlanGcEntity queryObject(String id) {
        return devPlanGcDao.queryObject(id);
    }

    /**
     * queryList
     *
     * @param map 参数
     * @return
     */
    @Override
    public List<DevPlanGcEntity> queryList(Map<String, Object> map) {
        return devPlanGcDao.queryList(map);
    }

    /**
     * queryTotal
     *
     * @param map 参数
     * @return
     */
    @Override
    public int queryTotal(Map<String, Object> map) {
        return devPlanGcDao.queryTotal(map);
    }

    /**
     * save
     *
     * @param devPlanGc 实体
     * @return
     */
    @Override
    public int save(DevPlanGcEntity devPlanGc) {
        devPlanGc.setRepairCode(J2CacheUtils.getSequence(4, "REP"));

        return devPlanGcDao.save(devPlanGc);
    }

    /**
     * update
     *
     * @param devPlanGc 实体
     * @return
     */
    @Override
    public int update(DevPlanGcEntity devPlanGc) {
        return devPlanGcDao.update(devPlanGc);
    }

    /**
     * delete
     *
     * @param id
     * @return
     */
    @Override
    public int delete(String id) {
        return devPlanGcDao.delete(id);
    }

    /**
     * deleteBatch
     *
     * @param ids
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteBatch(String[] ids) {
        return devPlanGcDao.deleteBatch(ids);
    }

    /**
     * queryObjectByPlanid
     *
     * @param id
     * @return
     */
    @Override
    public DevPlanGcEntity queryObjectByPlanid(String id) {
        return devPlanGcDao.queryObjectByPlanid(id);
    }

    /**
     * updataUrge
     *
     * @param status
     * @param id
     * @return
     */
    @Override
    public int updataUrge(Integer status, String id) {
        //设置为未催办
        if (status == 0) {
            //删除催办状态
            devReportUrgeService.delete(id);
        }
//        return devPlanGcDao.updataUrge(status, id);
        return 1;
    }

    /**
     * showT
     *
     * @param id
     * @return
     */
    @Override
    public int showT(String id) {
        return devPlanGcDao.showT(id);
    }

}
